

* Average cultural distance of European countries :
* 1. Graph average distance pre1999 and post2010, 45 degree line 
* 2. Event study analysis, graph coefficients and confidence intervals 


use "$data\pairwiseaverage_selectedquestions.dta", clear

global dist  dist_a001 dist_a030 dist_a035 dist_a038 dist_a041 dist_a042 dist_a165 dist_a173 dist_c001 dist_c002 dist_d001 dist_d057 dist_d061 dist_e023 dist_g006 dist_x026
label var dist_a030 "Child qualities: hard work"
label var dist_a035 "Child qualities: tolerance"
label var dist_a038 "Child qualities: thrift"
label var dist_c001 "Mens have more right to a job"
label var dist_a041 "Child qualities: unselfishness"
label var dist_a042 "Child qualities: obedience"
label var dist_a173 "Freedom of choice and control"
label var dist_c002 "Natives have more right to a job"
label var dist_d001 "Trust in family"
label var dist_d057 "Being housewife is fulfilling"
label var dist_d061 "Child suffers with working mother"
label var dist_g006 "Proud of nationality"
label var dist_x026 "Live with parents"

* Create pre1999 and post2010
drop s002 s002evs
keep macroarea* countryname* dist* s002vs 
global varname ""

********************************************************************************
*  Appendix G. Figure G3.
*  Average cultural distance of European countries before and after the EU enlargements

foreach d of varlist $dist {

preserve
keep macroarea* countryname* `d' s002vs 
local lab: variable label `d'
reshape wide `d', i(macroarea* countryname*) j(s002vs)
drop *4 *5
egen  `d'_pre = rmean(`d'1 `d'2 `d'3)
egen `d'_post = rmean(`d'6 `d'7)
drop `d'1 `d'2 `d'3 `d'6 `d'7

sum `d'_pre `d'_post
scalar max1 = r(max)
scalar min = r(min)
scalar max2 = -min
scalar max = max(max1, max2)
local max= max

sum `d'_pre
local obs_pre = r(N)

sum `d'_post
local obs_post = r(N)

gen eu2004 = 1 if (macroarea1 == "EU2004"| macroarea2=="EU2004")
replace eu2004 = 0 if missing(eu2004) 

gen eu2007 = 1 if  (macroarea2 == "EU2007"| macroarea1 == "EU2007") 
replace eu2007 = 0 if missing(eu2007)

drop if missing(`d'_post) | missing(`d'_pre)

if `obs_pre'!=0 & `obs_post'!=0{

global varname "$varname `d'"

twoway (scatter `d'_post `d'_pre if eu2004==1, msymbol(square) mcolor(dkorange)) ///
(scatter `d'_post `d'_pre  if eu2007==1, msymbol(triangle) mcolor(forest_green)) ///
(scatter `d'_post `d'_pre  if eu2004==0 & eu2007==0, msymbol(diamond) mcolor(edkblue)) ///
(function y=x, range(-`max' `max') color(gray)) ///
if strpos(macroarea1, "EU") & strpos(macroarea2, "EU"), ///
graphregion(color(white) lcolor(white))  xlabel(, nolabels) ylabel(, nolabels) ///
legend(order(1 "EU2004" 2 "EU2007" 3 "Other EU") cols(3) rowgap() symys(*.5) symxs(*.5) ///
size(small) region(c(none)) bm(tiny)) ytitle("Post-2010") ///
xtitle("Pre-1999")  title("`lab'") plotregion(lcolor(black))

graph rename `d', replace
}

restore
}

grc1leg $varname, graphregion(color(white) margin(zero)) cols(4) scale(.8)
graph export "$output/IVS_45linegraph.pdf", replace




use "$data\pairwiseaverage_selectedquestions.dta", replace

* Keep only distances 
keep macroarea* countryname* s002vs dist*

* Generate country-pairs identifiers
egen pair = group(countryname1 countryname2)
order pair, after(countryname2)

gen eu2004 = 1 if (macroarea1 == "EU2004"| macroarea2=="EU2004")
replace eu2004 = 0 if missing(eu2004) 
gen eu2007 = 1 if (macroarea2 == "EU2007"| macroarea1 == "EU2007") 
replace eu2007 = 0 if missing(eu2007)
label var eu2004 "newEU2004"
label var eu2007 "newEU2007"

*Create dummies for each wave and the interaction term between EU2004/EU2007 countries
*and the wave (excluding those in which the enlargements occurred, i.e., wave 4 and 5)

tab s002vs, g(s002vs)
gen int1_04 = eu2004*s002vs1
gen int2_04 = eu2004*s002vs2
gen int3_04 = eu2004*s002vs3 
gen int4_04 = eu2004*s002vs4
gen int5_04 = eu2004*s002vs5
gen int6_04 = eu2004*s002vs6
gen int7_04 = eu2004*s002vs7

gen int1_07 = eu2007*s002vs1
gen int2_07 = eu2007*s002vs2
gen int3_07 = eu2007*s002vs3
gen int4_07 = eu2007*s002vs4
gen int5_07 = eu2007*s002vs5 
gen int6_07 = eu2007*s002vs6
gen int7_07 = eu2007*s002vs7

label var int1_04 "eu2004*wave1"
label var int2_04 "eu2004*wave2"
label var int3_04 "eu2004*wave3"
label var int4_04 "eu2004*wave4"
label var int5_04 "eu2004*wave5"
label var int6_04 "eu2004*wave6"
label var int7_04 "eu2004*wave7"

label var int1_07 "eu2007*wave1"
label var int2_07 "eu2007*wave2"
label var int3_07 "eu2007*wave3"
label var int4_07 "eu2007*wave4"
label var int5_07 "eu2007*wave5"
label var int6_07 "eu2007*wave6"
label var int7_07 "eu2007*wave7"

global wave_fes "s002vs1 s002vs2 s002vs4 s002vs5 s002vs6 s002vs7"
gen b04 =.
gen b07 =.
gen se04 =.
gen se07 =.
global j =1
gen x =. 

global dist  dist_a001 dist_a030 dist_a035 dist_a038 dist_a041 dist_a042 dist_a165 dist_a173 dist_c001 dist_c002 dist_d001 dist_d057 dist_d061 dist_e023 dist_g006 dist_x026

label var dist_a030 "Child qualities: hard work"
label var dist_a035 "Child qualities: tolerance"
label var dist_a038 "Child qualities: thrift"
label var dist_c001 "Mens have more right to a job"
label var dist_a041 "Child qualities: unselfishness"
label var dist_a042 "Child qualities: obedience"
label var dist_a173 "Freedom of choice and control"
label var dist_c002 "Natives have more right to a job"
label var dist_d001 "Trust in family"
label var dist_d057 "Being housewife is fulfilling"
label var dist_d061 "Child suffers with working mother"
label var dist_g006 "Proud of nationality"
label var dist_x026 "Live with parents"

********************************************************************************
*  Appendix G. Figure G4.
*  Average cultural distance before and after the EU enlargements, DID estimates

foreach d of varlist $dist {

foreach n in 04 07{

foreach i of varlist int*_`n'{

areg `d' int1_04 int2_04 int4_04 int5_04 int6_04 int7_04 int1_07 int2_07 int4_07 int5_07 int6_07 int7_07 ///
$wave_fes if strpos(macroarea1, "EU") & strpos(macroarea2, "EU"), absorb(pair) cluster(pair) noomitted

cap: local b`n'`i' = _b[`i']

cap: local se`n'`i'= _se[`i']

if $j==1{
replace b`n' = `b`n'`i'' in $j if _n <8 
replace se`n' = `se`n'`i'' in $j if _n <8
replace x = $j in $j if _n <7
		}
if $j!=3{
replace b`n' = `b`n'`i'' in $j if _n <8
replace se`n' = `se`n'`i'' in $j if _n <8
replace x = $j in $j if _n<8

}
else{
replace b`n' = 0 in $j if _n <8
replace se`n' = 0 in $j if _n <8
replace x = $j in $j if _n<8

}
		global j = $j +1

}

global j =1
}

gen y = x+.05
gen z = x-.05

gen ubound04=b04+1.96*se04
gen lbound04=b04-1.96*se04
gen ubound07=b07+1.96*se07
gen lbound07=b07-1.96*se07

label define xlab 1 "Wave1" 2 "Wave2" 3 "Wave3" 4 "Wave4" 5 "Wave5" 6 "Wave6" 7 "Wave 7"
label values x xlab
local lab: variable label `d'

label define ylab 1 "Wave1" 2 "Wave2" 3 "Wave3" 4 "Wave4" 5 "Wave5" 6 "Wave6" 7 "Wave 7"
label values y ylab

label define zlab 1 "Wave1" 2 "Wave2" 3 "Wave3" 4 "Wave4" 5 "Wave5" 6 "Wave6" 7 "Wave 7"
label values z zlab

twoway ///
(rcap ubound04 lbound04 z, sort lcolor(edkblue) lwidth(medthick)) ///
(scatter b04 z, lcolor(navy) mcolor(dkorange) msize(vsmall)) ///
(rcap ubound07 lbound07 y, sort lcolor(cranberry) lwidth(medthick) xline(3, lcolor(gs15) lwidth(vvthick))) ///
(scatter b07 y, lcolor(dkgreen) mcolor(dkorange) msize(vsmall) yline(0, lcolor(black) lpattern(shortdash)) xticks()), ///
 graphregion(color(white)) ylabel(,labsize(vsmall))  ///
xlabel(1 "Wave1" 2 "Wave2" 3 "Wave3" 4 "Wave4" 5 "Wave5" 6 "Wave6" 7 "Wave7", angle(0) notick labsize(small)) xtitle("") ///
title("`lab'") legend(order(1 "EU2004" 3 "EU2007") pos(6) col(2) rowgap() symys(*.5) symxs(*.5) ///
size(vsmall) region(c(none)) bm(tiny))

ren `d' temp`d'
graph rename temp`d', replace

drop ubound* lbound* y z 
label drop xlab ylab zlab

}

describe tempdist_*, varlist
local varbles `r(varlist)'
*net install grc1leg
grc1leg `varbles', graphregion(color(white) margin(zero)) legendfrom(tempdist_a001)  cols(4) scale(.8)
graph export "$output/IVS_coeffCI.pdf", replace






